package com.xzssmk.leisure.x.controller;

import com.alibaba.fastjson.JSONObject;
import com.xzssmk.leisure.x.po.ScenicSpot;
import com.xzssmk.leisure.x.service.ReportStatisticsService;
import com.xzssmk.leisure.x.util.DataTables;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/report")
public class ReportStatisticsController {

    @Autowired
    private ReportStatisticsService reportStatisticsService;

    @RequestMapping(value = "/report-saleCard-state-list.html", method = RequestMethod.POST,
        produces = "application/json; charset=utf-8")
    @ResponseBody
    public String viewSaleCardStateReport(Integer issuePeriodId) {
        return JSONObject.toJSONString(reportStatisticsService.getSaleCardReportList(issuePeriodId));
    }

    @RequestMapping(value = "/viewSaleCardReport", method = RequestMethod.POST,
        produces = "application/json; charset=utf-8")
    @ResponseBody
    public String viewSaleCardReport(Integer issuePeriodId) {
        return JSONObject.toJSONString(reportStatisticsService.getSaleCardReportList(issuePeriodId));
    }

    @RequestMapping(value = "/getPageListPeriodLargess", method = RequestMethod.POST,
        produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getPageListPeriodLargess(HttpServletRequest request, String issuePeriodId, String storeLargessId) {
        return JSONObject.toJSONString(
            reportStatisticsService.bbPageList(DataTables.getInstance(request, null), issuePeriodId, storeLargessId));
    }

    @RequestMapping("/report-saleCard-list.html")
    public String saleCard() {
        return "report-saleCard-list";
    }

    @RequestMapping("/report-issueCard-income-list.html")
    public String issueCard() {
        return "report-issueCard-income-list";
    }

    @RequestMapping("/report-settlement-income-list.html")
    public String settlementIncome() {
        return "report-settlement-income-list";
    }

    @RequestMapping("/report-proportional-division-list.html")
    public String proportDivision() {
        return "report-proportional-division-list";
    }

    @RequestMapping("/report-consumption-division-list.html")
    public String consumpDivision() {
        return "report-consumption-division-list";
    }

    @RequestMapping("/report-weights-division-list.html")
    public String weightsDivision() {
        return "report-weights-division-list";
    }

    @RequestMapping("/report-saleCard-state-list.html")
    public String saleCardState() {
        return "report-saleCard-state-list";
    }

    @RequestMapping("/report-periodLargess-list.html")
    public String periodLargessReport() {
        return "report-periodLargess-list";
    }

    @RequestMapping(value = "/getPageList1", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getPageList(HttpServletRequest request) {
        // String subSQL = null;
        // if (!StringUtils.isEmpty(request.getParameter("fType"))) {
        // subSQL = "f_type = " + request.getParameter("fType");
        // }
        // if (!StringUtils.isEmpty(request.getParameter("timeMax"))) {
        // subSQL = StringUtils.isEmpty(subSQL) ? "" : subSQL + " and ";
        // subSQL += "f_time > '" + request.getParameter("timeMin") + "' and f_time < '" +
        // request.getParameter("timeMax") + "'";
        // }
        //
        return JSONObject.toJSONString(reportStatisticsService.getPageList1(DataTables.getInstance(request, null)));
    }


    /**
     * 比例分成报表
     */
    @RequestMapping("/report-proportion-list.html")
    public String commissionBbPage() {
        return "report-proportion-list";
    }

    @RequestMapping(value = "/getProportionPageList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getProportionPageList(HttpServletRequest request,String issuePeriodId) {
        return JSONObject.toJSONString(reportStatisticsService.proportionPageList(DataTables.getInstance(request, null), issuePeriodId));
    }


    /**
     * 刷卡情况统计报表
     */
    @RequestMapping("/report-sCard-list.html")
    public String sCardPage() {
        return "report-scard-list";
    }

    @RequestMapping(value = "/getSCardPageList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getSCardPageList(HttpServletRequest request,String issuePeriodId,String splitPattern) {
        return JSONObject.toJSONString(reportStatisticsService.getSCardPageList(DataTables.getInstance(request, null), issuePeriodId,splitPattern));
    }


    /**
     * 当期售卡统计报表
     */
    @RequestMapping("/report-order-list.html")
    public String orderPage() {
        return "report-order-list";
    }

    @RequestMapping(value = "/bbgetOrderList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String bbgetOrderList(HttpServletRequest request,String issuePeriodId,String purchaseMethod) {
        return JSONObject.toJSONString(reportStatisticsService.bbgetOrderList(DataTables.getInstance(request, null), issuePeriodId, purchaseMethod));
    }


    /**
     * 清分明细报表
     * 比例分成报表
     */
    @RequestMapping("/report-proportionCleanUp-list.html")
    public String proportion() {
        return "report-proportionCleanUp-list";
    }

    @RequestMapping(value = "/bbProportionCleanUpPageList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String bbProportionCleanUpPageList(HttpServletRequest request,String issuePeriodId,String scenicSpotId) {
        return JSONObject.toJSONString(reportStatisticsService.bbProportionCleanUpPageList(DataTables.getInstance(request, null), issuePeriodId, scenicSpotId));
    }

    /**
     * 商户端刷卡记录表
     */
    @RequestMapping("/report-swipeCard-list.html")
    public String swipeCardListHtml() {
        return "report-swipeCard-list";
    }

    @RequestMapping(value = "/swipeCardList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String swipeCardList(HttpServletRequest request,String issuePeriodId,String scenicSpotId) {
        ScenicSpot scenicSpot = (ScenicSpot) request.getSession().getAttribute("scenicSpot");
        return JSONObject.toJSONString(reportStatisticsService.swipeCardList(DataTables.getInstance(request, null), issuePeriodId, String.valueOf(scenicSpot.getScenicSpotId())));
    }


    /**
     * 卡片使用记录表
     */
    @RequestMapping("/report-cardUseHistory-list.html")
    public String cardUseHistoryHtml() {
        return "report-cardUseHistory-list";
    }

    @RequestMapping(value = "/cardUseHistory", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String cardUseHistory(HttpServletRequest request,String cardNumber) {
        return JSONObject.toJSONString(reportStatisticsService.cardUseHistory(DataTables.getInstance(request, null), cardNumber));
    }

    /**
     * 售卡统计报表
     */
    @RequestMapping("/report-saleCardCount-list.html")
    public String saleCardCountHtml() {
        return "report-saleCardCount-list";
    }

    @RequestMapping(value = "/saleCardCount", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String saleCardCount(HttpServletRequest request,String issuePeriodId) {
        return JSONObject.toJSONString(reportStatisticsService.bbSaleCardCountList(DataTables.getInstance(request, null), issuePeriodId));
    }

    /**
     * 发卡期收入报表
     */
    @RequestMapping("/report-issuePeriodInCome-list.html")
    public String issuePeriodInComeHtml() {
        return "report-issuePeriodInCome-list";
    }

    @RequestMapping(value = "/issuePeriodInCome", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String issuePeriodInCome(HttpServletRequest request,String issuePeriodId) {
        return JSONObject.toJSONString(reportStatisticsService.bbIssuePeriodInComeList(DataTables.getInstance(request, null), issuePeriodId));
    }
}
